package com.jueecy.controller;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class MailController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private JavaMailSender mailSender;

    @GetMapping("/sendMail")
    public boolean sendMail(String email,String xcode) {
        System.out.println(email+"***"+xcode);
        SimpleMailMessage message = new SimpleMailMessage();
        
        message.setFrom("2832640157@qq.com");
        message.setTo(email);
        message.setSubject("<验证码>");
        message.setText(xcode);
        System.out.println(message);
        try {
            mailSender.send(message);
            logger.info("邮箱验证码发送成功");
            return true;

        } catch (Exception e) {
            logger.error("邮箱验证码发送异常", e);
            return false;
        }

    }

}